Sound on Mobile
The sound quality of HTML5/WASM export on my mobile phone is awful. It’s delayed and stuttering. Although on desktop and also as a native Android export, everything sounds just fine. But on my phone (a Redmi Note 8T with Android 9) it’s so bad, I’d call it non functional.
The first attempt for a “solution”: Switching browsers on mobile. Because I’m using Opera on my phone, I thaught that it might be a bit obscure. So I ran the an HTML export on Chrome. But thas was no help either. The sound is barely bearable.
The next idea that came to mind was to convert the audio. Original I just took an MP3 as downloaded, which turned out to have a variable bitrate. Okay, that’s something that could cause problems, as MP3 support in Godot was only added with version 3. 2 in October 2020 (if I’m not mistaken). So I converted the MP3 files using Audacity to a constant and low bit rate. Turns out, again: that wasn’t the problem as audio on a smartphone still stutters. Neither did importing as OGG or WAV change anything.
After much googling I found two proposed solutions in a Godot’s Github issue #16259. The first and easiest idea was to allow for more audio delay in the project settings. That setting comes with a hefty warning to only change if one knows what one’s doing. Well, I don’k know what I did but at least I had a reason. It broke nothing but also didn’t fix anything.
Another proposed solution in Github issue #16259 requires to add an autoload. I’ve read that autoloads are bad (why?) and personally I don’t (yet) see a point in using them. But for the sake of fixing the stuttering audio on mobile I tried adding this:
Surprise, that didn’t work either.
The problem, as far as I understood, seems to be that the HTML5/ WASM export doesn’t support threads. That means there is only one loop running in which everything happens, the mainloop. I’d guess it would take some pretty sophisticated measures to make sure that the sound could be played at a constant and needed bitrate.
A solution seems to approach at the horizon: Godot 4. As I was waiting for Godot 3.1 for better mobile support with GLES 2.0, now I’m waiting for Godot again. This time version 4 for better audio on mobile.
Besides waiting there is one thing I can do: Add an optional mute button in every coming project. And maybe even mute it by default if I can detect on which system the game runs.